import java.util.Arrays;
import java.util.Random;

public class Test {
    //顺序
    public static void inorderArray(int[] array) {
        for(int i = 0;i < array.length;i++) {
            array[i] = i;
        }
    }
    //逆序
    public static void notInorderArray(int[] array) {
        for(int i = 0;i < array.length;i++) {
            array[i] = array.length - i;
        }
    }
    //乱序
    public static void initArray(int[] array) {
        Random random = new Random();
        for(int i = 0;i < array.length;i++) {
            array[i] = random.nextInt(array.length);
        }
    }
    public static void testInsertSort(int[] array) {
        int[] tmp = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(tmp);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入: " + (endTime - startTime));
    }
    public static void testShellSort(int[] array) {
        int[] tmp = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(tmp);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序: " + (endTime - startTime));
    }
    public static void testSelectSort(int[] array) {
        int[] tmp = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort1(tmp);
        long endTime = System.currentTimeMillis();
        System.out.println("直接选择:" + (endTime - startTime));
    }
    public static void testHeapSort(int[] array) {
        int[] tmp = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(tmp);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序:" + (endTime - startTime));
    }
    public static void testBubbleSort(int[] array) {
        int[] tmp = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(tmp);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序:" + (endTime - startTime));
    }

    public static void main(String[] args) {
        int[] array = new int[10000];
        initArray(array);
//        inorderArray(array);
//        notInorderArray(array);

        testInsertSort(array);
        testShellSort(array);
        testSelectSort(array);
        testHeapSort(array);
        testBubbleSort(array);
    }
    //测试
    public static void main1(String[] args) {
        int[] array = {4,7,2,5,8};
//        Sort.insertSort(array);
//        Sort.shellSort(array);
//        Sort.selectSort1(array);
//        Sort.selectSort2(array);
//        Sort.heapSort(array);
        Sort.bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }
}
